using System;
using System.Drawing;
using System.Windows.Forms;

namespace EForms
{
	public class StatusBarPanel : System.Windows.Forms.StatusBarPanel
	{
		StringFormat format = new StringFormat();
		
		public StatusBarPanel(string text)
		{
			Text = text;
			Style = StatusBarPanelStyle.OwnerDraw;
			BorderStyle = StatusBarPanelBorderStyle.None;
		}
		
		public StatusBarPanel()
		{
			Style = StatusBarPanelStyle.OwnerDraw;
			BorderStyle = StatusBarPanelBorderStyle.None;
		}
		
		public virtual void DrawPanel(StatusBarDrawItemEventArgs e)
		{
			Graphics g = e.Graphics;
			RectangleF b = new RectangleF(e.Bounds.X + 1,
			                              e.Bounds.Y + (e.Bounds.Height - e.Font.Height) / 2,
			                              e.Bounds.Width - 2,
			                              e.Bounds.Height -(e.Bounds.Height - e.Font.Height));
			
			switch(Alignment)
			{
				case HorizontalAlignment.Left:
					format.Alignment = StringAlignment.Near;
					break;
				case HorizontalAlignment.Center:
					format.Alignment = StringAlignment.Center;
					break;
				case HorizontalAlignment.Right:
					format.Alignment = StringAlignment.Far;
					break;
			}
			
			g.DrawString(Text, e.Font, SystemBrushes.ControlText, b, format);
			g.DrawRectangle(SystemPens.ControlDark, new Rectangle(e.Bounds.X,
			                                                      e.Bounds.Y,
			                                                      e.Bounds.Width - 1,
			                                                      e.Bounds.Height - 1)
			                                                      );
		}
	}
}
